Skip to content

Use curl instead of oc binary copy for testing kubeconfig#30927

Open
dgoodwin wants to merge 1 commit intoopenshift:mainfrom
dgoodwin:fix-oc-binary-glibc-problem
Open

Use curl instead of oc binary copy for testing kubeconfig#30927
dgoodwin wants to merge 1 commit intoopenshift:mainfrom
dgoodwin:fix-oc-binary-glibc-problem

Conversation

@dgoodwin
Copy link
Contributor

@dgoodwin dgoodwin commented Mar 24, 2026

The latter is causing problems on multi-arch and RHCOS 10.

This is quite ugly and a better version might be a good idea, but it did appear to work in the payload job run below. Coderabbit comment looks worth addressing, but we might want a cleaner version of this anyhow.

Hoping someone can pick this up and run it down to solve the two related bugs.

The latter is causing problems on multi-arch and rhcos mismatches
@openshift-ci-robot
Copy link

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

Walkthrough

The testKubeApiserverContainer function is refactored to validate the kube-apiserver using a direct curl HTTP call instead of copying the oc binary into the container and running oc get nodes. The new approach extracts TLS parameters from the kubeconfig file and invokes the kube-apiserver API endpoint directly.

Changes

Cohort / File(s) Summary
Kube-apiserver container test refactoring
test/extended/apiserver/kubeconfigs.go
Replaced oc binary copy and oc get nodes invocation with bash command that parses kubeconfig (server, client-certificate, client-key, certificate-authority) via grep/awk and issues direct TLS-authenticated curl call to kube-apiserver API endpoint. Error handling structure unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.3)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci bot requested review from deads2k and sjenning March 24, 2026 17:55
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 24, 2026
@dgoodwin
Copy link
Contributor Author

/payload-job periodic-ci-openshift-release-main-ci-4.22-e2e-aws-ovn-rhcos10-techpreview

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 24, 2026

@dgoodwin: trigger 1 job(s) for the /payload-(with-prs|job|aggregate|job-with-prs|aggregate-with-prs) command

  • periodic-ci-openshift-release-main-ci-4.22-e2e-aws-ovn-rhcos10-techpreview

See details on https://pr-payload-tests.ci.openshift.org/runs/ci/b4086a50-27aa-11f1-999d-88120be1b154-0

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/extended/apiserver/kubeconfigs.go`:
- Around line 121-125: The shell snippet that builds and runs the curl check
using kubeconfigPath should be hardened: change curl flags from -sf to -Ssf so
curl prints error details to stderr, and add defensive validation after
extracting server, cert, key, and ca (the variables produced by the grep/head
pipelines that reference kubeconfigPath) to ensure each field is present and
appears exactly once (e.g., check non-empty and unique counts) and fail with a
clear error message if validation fails; update the formatted command string
surrounding kubeconfigPath accordingly so failures are visible and mis-parsed
kubeconfigs cause immediate, informative test failures.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 28a15c7e-251d-4451-a7e1-55c0769a6869

📥 Commits

Reviewing files that changed from the base of the PR and between 15f465a and b273713.

📒 Files selected for processing (1)
  • test/extended/apiserver/kubeconfigs.go

Comment on lines +121 to +125
fmt.Sprintf(`server=$(grep 'server:' "%[1]s" | head -1 | awk '{print $2}')
cert=$(grep 'client-certificate:' "%[1]s" | head -1 | awk '{print $2}')
key=$(grep 'client-key:' "%[1]s" | head -1 | awk '{print $2}')
ca=$(grep 'certificate-authority:' "%[1]s" | head -1 | awk '{print $2}')
curl -sf --cert "$cert" --key "$key" --cacert "$ca" "${server}/api?timeout=32s"`, kubeconfigPath)).Output()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cd test/extended/apiserver && wc -l kubeconfigs.go

Repository: openshift/origin

Length of output: 78


🏁 Script executed:

cd test/extended/apiserver && sed -n '110,135p' kubeconfigs.go

Repository: openshift/origin

Length of output: 1251


🏁 Script executed:

cd test/extended/apiserver && sed -n '115,130p' kubeconfigs.go | cat -n

Repository: openshift/origin

Length of output: 1217


🏁 Script executed:

cd test/extended/apiserver && grep -B 5 -A 5 "kubeApiserverLocations" kubeconfigs.go | head -30

Repository: openshift/origin

Length of output: 1707


🏁 Script executed:

rg "verifyKubeconfig|verifyKubeapiserverKubeconfig" test/extended/apiserver/ -B 2 -A 2

Repository: openshift/origin

Length of output: 42


🌐 Web query:

curl -sf vs curl -Ssf flags difference stderr error output

💡 Result:

The difference between curl -sf and curl -Ssf (or curl -sSf) lies in how they handle stderr output for errors when running in silent mode. - curl -sf (silent + fail): Suppresses the progress meter and all error messages (no output to stderr on failure). On HTTP errors (e.g., 4xx/5xx), it fails with exit code 22 but produces no output at all, including no error message on stderr. - curl -Ssf (show-error + silent + fail): Suppresses the progress meter but shows an error message on stderr if the transfer fails (e.g., connection errors or HTTP errors due to -f). This is the common combination for scripts: quiet on success, visible error on stderr on failure for logging/monitoring (e.g., cron jobs). All diagnostic output (progress, verbose, errors) from curl goes to stderr by default. Response body goes to stdout. Examples: - Success (both): No stderr output. - HTTP 404 with -sf: Exit 22, empty stderr. - HTTP 404 with -Ssf: Exit 22, error like "curl: (22) The requested URL returned error: 404" on stderr. This behavior is consistent across recent curl versions (e.g., 8.x as of 2026).

Citations:


Improve test diagnostics by using curl -Ssf and add defensive validation for kubeconfig parsing.

The shell script extracts cert paths with grep | head -1 without validating that each field appears exactly once. While the test kubeconfigs are single-purpose, defensive validation prevents accidental mismatches. More importantly, curl -sf suppresses error output entirely, making failures opaque; switch to curl -Ssf to show errors to stderr for better test diagnostics.

Proposed hardening patch
-		fmt.Sprintf(`server=$(grep 'server:' "%[1]s" | head -1 | awk '{print $2}')
-cert=$(grep 'client-certificate:' "%[1]s" | head -1 | awk '{print $2}')
-key=$(grep 'client-key:' "%[1]s" | head -1 | awk '{print $2}')
-ca=$(grep 'certificate-authority:' "%[1]s" | head -1 | awk '{print $2}')
-curl -sf --cert "$cert" --key "$key" --cacert "$ca" "${server}/api?timeout=32s"`, kubeconfigPath)).Output()
+		fmt.Sprintf(`cfg="%[1]s"
+for k in server client-certificate client-key certificate-authority; do
+  c=$(grep -Ec "^[[:space:]]*${k}:[[:space:]]+" "$cfg")
+  [ "$c" -eq 1 ] || { echo "expected exactly one ${k} in $cfg, got $c" >&2; exit 1; }
+done
+server=$(grep -m1 -E "^[[:space:]]*server:[[:space:]]+" "$cfg" | awk '{print $2}')
+cert=$(grep -m1 -E "^[[:space:]]*client-certificate:[[:space:]]+" "$cfg" | awk '{print $2}')
+key=$(grep -m1 -E "^[[:space:]]*client-key:[[:space:]]+" "$cfg" | awk '{print $2}')
+ca=$(grep -m1 -E "^[[:space:]]*certificate-authority:[[:space:]]+" "$cfg" | awk '{print $2}')
+curl -Ssf --cert "$cert" --key "$key" --cacert "$ca" "${server}/api?timeout=32s"`, kubeconfigPath)).Output()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fmt.Sprintf(`server=$(grep 'server:' "%[1]s" | head -1 | awk '{print $2}')
cert=$(grep 'client-certificate:' "%[1]s" | head -1 | awk '{print $2}')
key=$(grep 'client-key:' "%[1]s" | head -1 | awk '{print $2}')
ca=$(grep 'certificate-authority:' "%[1]s" | head -1 | awk '{print $2}')
curl -sf --cert "$cert" --key "$key" --cacert "$ca" "${server}/api?timeout=32s"`, kubeconfigPath)).Output()
fmt.Sprintf(`cfg="%[1]s"
for k in server client-certificate client-key certificate-authority; do
c=$(grep -Ec "^[[:space:]]*${k}:[[:space:]]+" "$cfg")
[ "$c" -eq 1 ] || { echo "expected exactly one ${k} in $cfg, got $c" >&2; exit 1; }
done
server=$(grep -m1 -E "^[[:space:]]*server:[[:space:]]+" "$cfg" | awk '{print $2}')
cert=$(grep -m1 -E "^[[:space:]]*client-certificate:[[:space:]]+" "$cfg" | awk '{print $2}')
key=$(grep -m1 -E "^[[:space:]]*client-key:[[:space:]]+" "$cfg" | awk '{print $2}')
ca=$(grep -m1 -E "^[[:space:]]*certificate-authority:[[:space:]]+" "$cfg" | awk '{print $2}')
curl -Ssf --cert "$cert" --key "$key" --cacert "$ca" "${server}/api?timeout=32s"`, kubeconfigPath)).Output()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/extended/apiserver/kubeconfigs.go` around lines 121 - 125, The shell
snippet that builds and runs the curl check using kubeconfigPath should be
hardened: change curl flags from -sf to -Ssf so curl prints error details to
stderr, and add defensive validation after extracting server, cert, key, and ca
(the variables produced by the grep/head pipelines that reference
kubeconfigPath) to ensure each field is present and appears exactly once (e.g.,
check non-empty and unique counts) and fail with a clear error message if
validation fails; update the formatted command string surrounding kubeconfigPath
accordingly so failures are visible and mis-parsed kubeconfigs cause immediate,
informative test failures.

@openshift-ci-robot
Copy link

Scheduling required tests:
/test e2e-aws-csi
/test e2e-aws-ovn-fips
/test e2e-aws-ovn-microshift
/test e2e-aws-ovn-microshift-serial
/test e2e-aws-ovn-serial-1of2
/test e2e-aws-ovn-serial-2of2
/test e2e-gcp-csi
/test e2e-gcp-ovn
/test e2e-gcp-ovn-upgrade
/test e2e-metal-ipi-ovn-ipv6
/test e2e-vsphere-ovn
/test e2e-vsphere-ovn-upi

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 24, 2026

@dgoodwin: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@prb112
Copy link
Contributor

prb112 commented Mar 25, 2026

Thanks!
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 25, 2026
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 25, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dgoodwin, prb112

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants